Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 25, 2026

Addresses 8 review comments on PR #5 covering unused imports, non-deterministic assertions, and overly broad exception handling in test_routes.py.

Import cleanup

  • Removed unused MagicMock and top-level LockError imports

Deterministic test assertions

  • test_enqueue_get_queue_length_exception: Changed assertIn(status_code, [201, 400]) to deterministic assertEqual(201) - when get_queue_length fails, enqueue proceeds with current_queue_length=0
  • test_clear_queue_malformed_json: Now sends actual malformed JSON via client.request("DELETE", ...) instead of mocking

Exception handling specificity

  • Replaced except Exception with except asyncio.CancelledError in lifespan tests
  • Replaced bare except: with except asyncio.CancelledError
  • Removed unused response variable in test_deep_status_exception

Test isolation improvements

  • test_requeue_with_lock_lock_error: Properly mocks async context manager to exercise LockError path
  • test_lifespaninitializes_queue: Stubs requeue_with_lock to prevent uninitialized queue access during startup/shutdown testing
# Before: non-deterministic
self.assertIn(response.status_code, [201, 400])

# After: deterministic with clear expectations
self.assertEqual(response.status_code, 201)
self.assertEqual(response.json()["status"], "queued")
self.assertEqual(response.json()["current_queue_length"], 0)

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…and exception handling

Co-authored-by: ochui <21917688+ochui@users.noreply.github.com>
Copilot AI changed the title [WIP] Add tests to cover exception and edge cases in server routes Address code review feedback: fix test assertions and exception handling Jan 25, 2026
Copilot AI requested a review from ochui January 25, 2026 21:32
Refactors the test to use a custom async context manager that raises
the lock error, providing more accurate simulation of lock acquisition
failure. Removes unnecessary assertions on mock calls for clarity.
@coderabbitai
Copy link

coderabbitai bot commented Jan 25, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

@ochui ochui marked this pull request as ready for review January 25, 2026 21:41
Copilot AI review requested due to automatic review settings January 25, 2026 21:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request addresses code review feedback from PR #5 by improving test quality and maintainability. The changes focus on removing unused imports, making test assertions deterministic, and making exception handling more specific in the test suite.

Changes:

  • Removed unused imports (MagicMock and top-level LockError) and moved LockError to local import where needed
  • Fixed non-deterministic test assertions by replacing assertIn(status_code, [201, 400]) with deterministic assertEqual(201) and added explicit response validation
  • Replaced overly broad exception handling (except Exception, except:) with specific except asyncio.CancelledError in lifespan tests
  • Improved test isolation by properly mocking async context managers and stubbing background tasks to prevent uninitialized queue access
  • Updated test_clear_queue_malformed_json to send actual malformed JSON instead of mocking
  • Removed unused response variable in test_deep_status_exception

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ochui ochui merged commit 3ced2a8 into test/coverage Jan 25, 2026
7 checks passed
@ochui ochui deleted the copilot/sub-pr-5 branch January 25, 2026 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants